package com.china08.yxyapi.api.home.weikecheng;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.res.YxyResBookContents;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyResBookContentsRepository;

/**
 * 微课首页按目录初始化 不需要登陆
 * 
 */
@CrossOrigin
@RestController
public class WeikeHomeContentNoAuthController extends YxyApiBaseController {

    @Autowired
    private YxyResBookContentsRepository yrbcr;

    @ResponseBody
    @RequestMapping(value = "/api_yw/home/weike/content/not/auth/init", method = RequestMethod.GET)
    public RespModel process(HttpServletRequest request, HttpServletResponse response)
            throws IllegalAccessException, InvocationTargetException {

        // ##
        RespModel model = new RespModel();

        List<YxyResBookContents> listcoContents = yrbcr.findByBookIdAndIsViewOrderByOrderNum(model.getBookId(), 1);
        BookContentRespModel respModel = null;
        for (YxyResBookContents yxyResBookContents : listcoContents) {
            respModel = new BookContentRespModel();
            respModel.setId(yxyResBookContents.getId());
            respModel.setName(yxyResBookContents.getName());
            respModel.setpId(yxyResBookContents.getpId());
            model.getBookContent().add(respModel);
        }

        model.setMessage("成功");
        return model;
    }

    protected static class BookContentRespModel {
        public String id;
        public String pId;
        public String name;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getpId() {
            return pId;
        }

        public void setpId(String pId) {
            this.pId = pId;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }

    public static class RespModel extends YxyApiRespModel {

        public String phaseName = "小学";

        public String subjectName = "数学";

        public String versionName = "人教课标版";

        public String phase = "01";

        public String subject = "jcsub02";

        public String version = "bb08";

        public String semester = "V008";

        public String semesterName = "一年级上册";

        public String bookId = "21354";

        public List<BookContentRespModel> bookContent = new ArrayList<BookContentRespModel>();

        public String getPhaseName() {
            return phaseName;
        }

        public void setPhaseName(String phaseName) {
            this.phaseName = phaseName;
        }

        public String getSubjectName() {
            return subjectName;
        }

        public void setSubjectName(String subjectName) {
            this.subjectName = subjectName;
        }

        public String getVersionName() {
            return versionName;
        }

        public void setVersionName(String versionName) {
            this.versionName = versionName;
        }

        public String getPhase() {
            return phase;
        }

        public void setPhase(String phase) {
            this.phase = phase;
        }

        public String getSubject() {
            return subject;
        }

        public void setSubject(String subject) {
            this.subject = subject;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }

        public String getSemester() {
            return semester;
        }

        public void setSemester(String semester) {
            this.semester = semester;
        }

        public String getSemesterName() {
            return semesterName;
        }

        public void setSemesterName(String semesterName) {
            this.semesterName = semesterName;
        }

        public String getBookId() {
            return bookId;
        }

        public void setBookId(String bookId) {
            this.bookId = bookId;
        }

        public List<BookContentRespModel> getBookContent() {
            return bookContent;
        }

        public void setBookContent(List<BookContentRespModel> bookContent) {
            this.bookContent = bookContent;
        }

    }

}
